package xj.meta;

/**********************************************************************************
 *
 * @author Xiaoping Jia
 * @version 0.2
 *
 * Created on: 2005/05/01
 * Requires: J2SE 5.0
 *
 **********************************************************************************/

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Stereotype implements Cloneable {

  public Stereotype(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Set<String> getSuperClasses() {
    return superClasses;
  }

  public void addSuperClass(String s) {
    if (s != null) {
      if (superClasses == null) {
	superClasses = new HashSet<String>();
      }
      superClasses.add(s);
    }
  }

  public void removeSuperClass(String s) {
    if (s != null && 
	superClasses != null) {
      superClasses.remove(s);
    }
  }

  public Map<String, String> getTags() {
    return tags;
  }

  public void setTags(Map<String, String> tags) {
    this.tags = tags;
  }

  public void removeAllTags() {
    tags.clear();
  }

  public String getTagValue(String t) {
    if (t != null) {
      return tags.get(t);
    }
    return null;
  }

  public void setTagValue(String tag, String value) {
    if (tag != null && value != null) {
      tags.put(tag, value);
    }
  }

  public void removeTag(String t) {
    if (t != null) {
      tags.remove(t);
    }
  }

  @Override
  public Object clone() throws CloneNotSupportedException {
    Stereotype c = (Stereotype) super.clone();
    c.name = name;

    c.superClasses = new HashSet<String>();
    if (superClasses != null) {
      c.superClasses.addAll(superClasses);
    }

    c.tags = new HashMap<String, String>();
    if (tags != null) {
      Set<String> keys = tags.keySet();
      Iterator<String> kiter = keys.iterator();
      while (kiter.hasNext()) {
	String k = kiter.next();
	c.tags.put(k, tags.get(k));
      }
    }
    return c;
  }

  protected String name;

  protected Set<String> superClasses;

  protected Map<String, String> tags = new HashMap<String, String>();

}
